Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Change SymbolContext::GetAddressRangeFromHereToEndLine to return Expected (NFC) #110718

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

AbdAlRahmanGad
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Oct 1, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the lldb label Oct 1, 2024
@AbdAlRahmanGad
Copy link
Contributor Author

@adrian-prantl

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 1, 2024

@llvm/pr-subscribers-lldb

Author: AbdAlRahman Gad (AbdAlRahmanGad)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/110718.diff

4 Files Affected:

  • (modified) lldb/include/lldb/Symbol/SymbolContext.h (+2-2)
  • (modified) lldb/source/API/SBThread.cpp (+7-1)
  • (modified) lldb/source/Commands/CommandObjectThread.cpp (+8-5)
  • (modified) lldb/source/Symbol/SymbolContext.cpp (+8-13)
diff --git a/lldb/include/lldb/Symbol/SymbolContext.h b/lldb/include/lldb/Symbol/SymbolContext.h
index 0bc707070f8504..653e414d9aa4f1 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -201,8 +201,8 @@ class SymbolContext {
   bool GetAddressRange(uint32_t scope, uint32_t range_idx,
                        bool use_inline_block_range, AddressRange &range) const;
 
-  bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range,
-                                        Status &error);
+  llvm::Expected<bool> GetAddressRangeFromHereToEndLine(uint32_t end_line,
+                                                        AddressRange &range);
 
   /// Find the best global data symbol visible from this context.
   ///
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index 7508eed5d6fdbd..76c321e6df90f8 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -605,8 +605,14 @@ void SBThread::StepInto(const char *target_name, uint32_t end_line,
     if (end_line == LLDB_INVALID_LINE_NUMBER)
       range = sc.line_entry.range;
     else {
-      if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
+      auto get_address_range_from_here_to_end_line_or_err =
+          sc.GetAddressRangeFromHereToEndLine(end_line, range);
+      if (!get_address_range_from_here_to_end_line_or_err) {
+        error = Status::FromErrorString(
+            toString(get_address_range_from_here_to_end_line_or_err.takeError())
+                .c_str());
         return;
+      }
     }
 
     const LazyBool step_out_avoids_code_without_debug_info =
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index edbec0e305db74..d9ae4590773995 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -489,11 +489,14 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
         AddressRange range;
         SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
         if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
-          Status error;
-          if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range,
-                                                   error)) {
-            result.AppendErrorWithFormat("invalid end-line option: %s.",
-                                         error.AsCString());
+          auto get_address_range_from_here_to_end_line_or_err =
+              sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range);
+          if (!get_address_range_from_here_to_end_line_or_err) {
+            result.AppendErrorWithFormat(
+                "invalid end-line option: %s.",
+                toString(
+                    get_address_range_from_here_to_end_line_or_err.takeError())
+                    .c_str());
             return;
           }
         } else if (m_options.m_end_line_is_block_end) {
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index a1020a5aae4e79..ac7864cb3a6623 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -706,20 +706,18 @@ LineEntry SymbolContext::GetFunctionStartLineEntry() const {
   return LineEntry();
 }
 
-bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
-                                                     AddressRange &range,
-                                                     Status &error) {
+llvm::Expected<bool>
+SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
+                                                AddressRange &range) {
   if (!line_entry.IsValid()) {
-    error = Status::FromErrorString("Symbol context has no line table.");
-    return false;
+    return llvm::createStringError("Symbol context has no line table.");
   }
 
   range = line_entry.range;
   if (line_entry.line > end_line) {
-    error = Status::FromErrorStringWithFormat(
+    return llvm::createStringError(
         "end line option %d must be after the current line: %d", end_line,
         line_entry.line);
-    return false;
   }
 
   uint32_t line_index = 0;
@@ -740,29 +738,26 @@ bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
   if (!found) {
     // Can't find the index of the SymbolContext's line entry in the
     // SymbolContext's CompUnit.
-    error = Status::FromErrorString(
+    return llvm::createStringError(
         "Can't find the current line entry in the CompUnit - can't process "
         "the end-line option");
-    return false;
   }
 
   line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
                                         &end_entry);
   if (line_index == UINT32_MAX) {
-    error = Status::FromErrorStringWithFormat(
+    return llvm::createStringError(
         "could not find a line table entry corresponding "
         "to end line number %d",
         end_line);
-    return false;
   }
 
   Block *func_block = GetFunctionBlock();
   if (func_block && func_block->GetRangeIndexContainingAddress(
                         end_entry.range.GetBaseAddress()) == UINT32_MAX) {
-    error = Status::FromErrorStringWithFormat(
+    return llvm::createStringError(
         "end line number %d is not contained within the current function.",
         end_line);
-    return false;
   }
 
   lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -

Signed-off-by: AbdAlRahman Gad <[email protected]>
@adrian-prantl
Copy link
Collaborator

Thanks, this looks nice!

@adrian-prantl adrian-prantl self-requested a review October 8, 2024 17:04
@adrian-prantl adrian-prantl merged commit 6f2ebc4 into llvm:main Oct 8, 2024
7 checks passed
Copy link

github-actions bot commented Oct 8, 2024

@AbdAlRahmanGad Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants